from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options
from service import service

class Bagepage():
    def __init__(self,dr):
        '''封装构造方法'''
        self.dr=dr
    def get_url(self,url):
        '''实现：打开 url 页面'''
        self.dr.get(url)
        self.dr.maximize_window()
    def find_ele(self,loc):
        '''元素定位'''
        ele=self.dr.find_element(*loc)
        return ele
    def input_element(self,loc,value):
        '''文本框输入内容'''
        ele = self.find_ele(loc)
        ele.send_keys(value)

    def click(self,loc):
        '''点击'''
        ele=self.find_ele(loc)
        ele.click()
    def clear(self,loc):
        '''清空文本框内容'''
        ele=self.find_ele(loc)
        ele.clear()
if __name__ == '__main__':
    url=r'https://www.baidu.com/'
    kw_loc=(By.ID,'kw')
    su_loc=(By.ID,'su')
    value = 'hello'
    dr=webdriver.Chrome(options=options,service=service)


    bage=Bagepage(dr)
    bage.get_url(url)
    bage.clear(kw_loc)
    bage.input_element(kw_loc,value)
    bage.click(su_loc)
    sleep(3)
    dr.quit()


